using System;
using System.Collections.Generic;
using System.Reflection;
using Nebulosa.Data.Orm;
using Nebulosa.Data.Hal;


namespace Nebulosa.Data.Providers {
	public class NebulosaProvider : IProvider {
		protected HalCore hal;
		
		public NebulosaProvider() {
			this.hal = new HalCore();
		}
		
		public void Insert<T>(T model) {
			DbProvider.Trace = "";
			DbProvider.Trace += "<br/>Nebulosa insert  " + model.GetType();
			
			List<PropertyInfo> pks = this.Cast<Model>(model).GetPrimaryKeys();
			DbProvider.Trace += "<br/>PKS";
			for(int i = 0; i < pks.Count; i++) {
				DbProvider.Trace += "<br/>" + pks[i].Name;
			}
			
			this.hal.Insert(model);
			
			this.hal.Save();
		}
		
		public void Update<T>(T model) {
			
		}
		
		public void Delete<T>(T model) {
			
		}
		
		public Model Get<T>(T model) {
			DbProvider.Trace += "Nebulosa get ";
			
			return this.hal.Get(model);
		}
		
		protected T Cast<T>(object o) {
			return (T)o;
		}
	}
}